<include file="../Public/header" />
<div id="content">
    <div id="user-sendmsg" data-title="发私信" date-selected="true" data-footer="none" data-rememberScroll="true">
      <header>
        <div id="header-buttons">
          <div id="back" class="header-menu-link">
          </div>
            <div class="header-menu-link" id="hmp-send">
                <a class="sendBtn disable" onclick="doPostMessage();" id="postbut" href="javascript:;">发送</a>
            </div>
        </div>
        <h1 style="text-align:center;">
            发私信
        </h1>
      </header>
      <div class="pop-message" id='post_message'>  
        <div>{:W('SearchUser',array('uids'=>$touid,'max'=>1,'editable'=>$touid?0:1,'tpl'=>'w3g_SearchUser.html'))}</div>
        <div class="pure-form send_box"><textarea id="message_content" class="ts-textarea" rows="4" placeholder="输入私信内容"></textarea></div>
        <div class="ts-footer">
                  <!-- 表情 --><a class="icon facelistbutton ts-listen" data-listen="weibo-facelist-show"><i class="fa-btn fa-btn-smile"></i></a>
                  <!-- 图片 --><a class="icon imgbutton ts-listen" data-listen="weibo-upload-img" data-for="ts-upload-img-box" id="new-weibo-upload"><i class="fa-btn fa-btn-picture"></i></a>
                  
                  <!-- <a class="face-block" href="javascript:;" event-node="message_insert_face" title="表情"><i class="face"></i></a>
                  <a class="image-block" href="javascript:;" title="图片"><i class="image"></i>
                    <form style='display:inline;padding:0;margin:0;border:0;outline:none;' enctype="multipart/form-data">
                      <input type="file" name="attach" limit="2" inputname='attach' onchange="core.plugInit('uploadFile',this,'','image')" urlquery='attach_type=message_image&upload_type=image&thumb=1&width=100&height=100&cut=1' hidefocus="true">
                    </form>
                  </a>
                  <a class="file-block" href="javascript:;" title="附件"><i class="file"></i>
                        <form style='display:inline;padding:0;margin:0;border:0'  enctype="multipart/form-data">
                         <input limit="2" type="file" name="attach_file" inputname='attach' onchange="core.plugInit('uploadFile',this,'','all')" urlquery='attach_type=message_file&upload_type=file' hidefocus="true">
                        </form>
                  </a> -->
                  <!-- <div id="message_face_div"></div> -->
        </div>
        <div id="ts-upload-img-box"></div>
      </div>

      <script type="text/javascript">
      M.addEventFns({
        message_insert_face: {
          click: function () {
            var target = $('#message_content')[0];
            var parentDiv = $('#message_face_div')[0];
            core.plugInit('face', this, $('#message_content'), parentDiv);
          }
        }
      });
      // 重新监听事件
      M(document.getElementById('post_message'));
      shortcut('ctrl+return', doPostMessage , {target:'post_message'});
      /**
       * 按钮状态
       * @param string type 状态类型，2种
       * @return void
       */
      function butstate(type){
      	if(type == 'open') {
      		$('#postbut').removeAttr('disabled');
      		$('#postbut').val("发送");
      	}
      	if(type == 'close') {
      		$('#postbut').attr('disabled','true');
      		$('#postbut').val('Loading......');
      	}
      }
      var send = 0;
      /**
       * 发送私信操作
       * @return void
       */
      function doPostMessage() {
          if(send === 1){
              return false;
          }
      	// 发送私信的用户
          var message_to = $('#search_uids').val();
          if("undefined" == typeof(message_to)) {
              $.ui.showMask("收信人不能为空", true);
              return false;
          }
          // 限制发送用户的个数
          if(message_to.split(",").length > 12){
          	// ui.error('私信最多只能同时发送给10个人')
          	return false;
          }
          
          //var message_title = $('#message_title').val();
          var message_content = $('#message_content').val();
          // 验证发送信息正确性
          if(message_to == "") {
          	$.ui.showMask("收信人不能为空", true);
          	//butstate('open');
          	return false;
          }
//          if(message_title == "") {
//          	$.ui.showMask("标题不可为空", true);
//          	//butstate('open');
//          	return false;
//          }
          if(message_content == "") {
          	$.ui.showMask("内容不可为空", true);
          	//butstate('open');
          	return false;
          }
          send = 1;
          var attach_ids = $.trim($('#attach_ids').val());
          // 发送按钮状态
          //butstate('close');
          // 发送私信链接
          $.post("{:U('public/Message/doPost')}", {to:message_to, content:message_content, attach_ids:attach_ids}, function(res) {
              if(res.status == 1){
//                  $.ui.showMask("发送成功", true);
                  TS.showMaskOK();
                  location.href = U('w3g/Index/msgbox') + '#msg';
                  //ui.box.close();
              } else {
                  $.ui.showMask(res.data, true);
                  send = 0;
                  //butstate('open');
              }
          }, 'json');
      };
      </script>
      </div>
  <include file="../Public/footer" />